﻿//-----------------------------------------------------------------------
// <copyright file="SQLDataProviderTest.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Data.EntityClient;
using GateShift.Common.Repository.Interfaces.Repositories;
using GateShift.Common.Repository.Interfaces.Repositories.Base;
using GateShift.Services.GameData;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace GateShift.Testing.Services.GameData
{
    /// <summary>
    /// Summary description for SQLDataProviderTest
    /// </summary>
    [TestClass]
    public class SQLDataProviderTest
    {
        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        [TestMethod]
        public void GetRepository_RepositoriesExist()
        {
            SQLDataProvider provider = new SQLDataProvider();

            Assert.IsNotNull(provider.GetRepository<IAccountRepository>(), "IAccountRepository does not exist.");
            Assert.IsNotNull(provider.GetRepository<IGuildRankRepository>(), "IGuildRankRepository does not exist.");
            Assert.IsNotNull(provider.GetRepository<IGuildRepository>(), "IGuildRepository does not exist.");
            Assert.IsNotNull(provider.GetRepository<IRaceRepository>(), "IRaceRepository does not exist.");
            Assert.IsNotNull(provider.GetRepository<ICharacterRepository>(), "ICharacterRepository does not exist.");
            Assert.IsNotNull(provider.GetRepository<IGuildMemberRepository>(), "IGuildMemberRepository does not exist.");
            Assert.IsNotNull(provider.GetRepository<IClassRepository>(), "IClassRepository does not exist.");
            Assert.IsNotNull(provider.GetRepository<ICharacterClassRepository>(), "ICharacterClassRepository does not exist.");

            Assert.AreEqual(8, SQLDataProvider_Accessor._repositories.Count, "Count Mismatch. New Repositories Exist?");
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void GetRepository_ThrowsExceptionWhenNotFound()
        {
            SQLDataProvider provider = new SQLDataProvider();

            provider.GetRepository<IRepository>();
        }

        [TestMethod]
        public void VerifyConnection()
        {
            // Create a new static class if one does not exist
            new SQLDataProvider();

            EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder
                                                        {
                                                            Metadata = "res://*/Entities.GateShiftEntities.csdl|res://*/Entities.GateShiftEntities.ssdl|res://*/Entities.GateShiftEntities.msl",
                                                            Provider = "System.Data.SqlClient",
                                                            ProviderConnectionString = GateShift.Services.GameData.Properties.Settings.Default.GateShiftConnectionString
                                                        };

            Assert.AreEqual(builder.ConnectionString, SQLDataProvider_Accessor._connection.ConnectionString, "Connection string Mismatch");
        }
    }
}